package com.ruoyi.performancesys.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.RandomUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;

import com.ruoyi.employeeInfomation.domain.SalaryEmployee;
import com.ruoyi.employeeInfomation.mapper.SalaryEmployeeMapper;
import com.ruoyi.performancesys.vo.PerformanceVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.performancesys.mapper.SalaryPerformanceMapper;
import com.ruoyi.performancesys.domain.SalaryPerformance;
import com.ruoyi.performancesys.service.ISalaryPerformanceService;

/**
 * 绩效管理Service业务层处理
 *
 * @author ruoyi
 * @date 2024-08-12
 */
@Service
public class SalaryPerformanceServiceImpl extends ServiceImpl<SalaryPerformanceMapper, SalaryPerformance> implements ISalaryPerformanceService {
    @Autowired
    private SalaryPerformanceMapper salaryPerformanceMapper;
    @Autowired
    private SalaryEmployeeMapper salaryEmployeeMapper;

    /**
     * 查询绩效管理
     *
     * @param id 绩效管理主键
     * @return 绩效管理
     */
    @Override
    public SalaryPerformance selectSalaryPerformanceById(Long id) {
        return salaryPerformanceMapper.selectSalaryPerformanceById(id);
    }

    /**
     * 查询绩效管理列表
     *
     * @param salaryPerformance 绩效管理
     * @return 绩效管理
     */
    @Override
    public List<SalaryPerformance> selectSalaryPerformanceList(SalaryPerformance salaryPerformance) {
        return salaryPerformanceMapper.selectSalaryPerformanceList(salaryPerformance);
    }

    /**
     * 新增绩效管理
     *
     * @param salaryPerformance 绩效管理
     * @return 结果
     */
    @Override
    public int insertSalaryPerformance(PerformanceVo performanceVo) {
        SalaryEmployee salaryEmployee = new SalaryEmployee();
        SalaryPerformance salaryPerformance = new SalaryPerformance();
        List<SalaryEmployee> list = salaryEmployeeMapper.selectSalaryEmployeeList(salaryEmployee);
        for (SalaryEmployee emp:list) {
            if(performanceVo.getJobNumber().equals(emp.getJobNumber())){
                salaryPerformance.setEmployeeId(emp.getId());
            }
        }
        BeanUtil.copyProperties(performanceVo,salaryPerformance);
        salaryPerformance.setContractTicketNumber(String.valueOf(RandomUtil.randomLong(1000000000000000L, 9999999999999999L)));
        return salaryPerformanceMapper.insertSalaryPerformance(salaryPerformance);
    }

    /**
     * 修改绩效管理
     *
     * @param salaryPerformance 绩效管理
     * @return 结果
     */
    @Override
    public int updateSalaryPerformance(SalaryPerformance salaryPerformance) {
        return salaryPerformanceMapper.updateSalaryPerformance(salaryPerformance);
    }

    /**
     * 批量删除绩效管理
     *
     * @param ids 需要删除的绩效管理主键
     * @return 结果
     */
    @Override
    public int deleteSalaryPerformanceByIds(Long[] ids) {
        return salaryPerformanceMapper.deleteSalaryPerformanceByIds(ids);
    }

    /**
     * 删除绩效管理信息
     *
     * @param id 绩效管理主键
     * @return 结果
     */
    @Override
    public int deleteSalaryPerformanceById(Long id) {
        return salaryPerformanceMapper.deleteSalaryPerformanceById(id);
    }
}